<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
                      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
    <title>Using Different Transports - Zend Framework Manual</title>

    <link href="../css/shCore.css" rel="stylesheet" type="text/css" />
    <link href="../css/shThemeDefault.css" rel="stylesheet" type="text/css" />
    <link href="../css/styles.css" media="all" rel="stylesheet" type="text/css" />
</head>
<body>
<h1>Zend Framework</h1>
<h2>Programmer's Reference Guide</h2>
<ul>
    <li><a href="../en/zend.mail.different-transports.html">Inglês (English)</a></li>
    <li><a href="../pt-br/zend.mail.different-transports.html">Português Brasileiro (Brazilian Portuguese)</a></li>
</ul>
<table width="100%">
    <tr valign="top">
        <td width="85%">
            <table width="100%">
                <tr>
                    <td width="25%" style="text-align: left;">
                    <a href="zend.mail.multiple-emails.html">Sending Multiple Mails per SMTP Connection</a>
                    </td>

                    <td width="50%" style="text-align: center;">
                        <div class="up"><span class="up"><a href="zend.mail.html">Zend_Mail</a></span><br />
                        <span class="home"><a href="manual.html">Guia de Refer&ecirc;ncia do Programador</a></span></div>
                    </td>

                    <td width="25%" style="text-align: right;">
                        <div class="next" style="text-align: right; float: right;"><a href="zend.mail.html-mails.html">HTML E-Mail</a></div>
                    </td>
                </tr>
            </table>
<hr />
<div id="zend.mail.different-transports" class="section"><div class="info"><h1 class="title">Using Different Transports</h1></div>
    

    <p class="para">
        In case you want to send different e-mails through different connections, you can also pass
        the transport object directly to  <span class="methodname">send()</span> without a prior call to
         <span class="methodname">setDefaultTransport()</span>. The passed object will override the default
        transport for the actual  <span class="methodname">send()</span> request.
    </p>

    <div class="example" id="zend.mail.different-transports.example-1"><div class="info"><p><b>Example #1 Using Different Transports</b></p></div>
        

        <pre class="programlisting brush: php">
$mail = new Zend_Mail();
// build message...
$tr1 = new Zend_Mail_Transport_Smtp(&#039;server@example.com&#039;);
$tr2 = new Zend_Mail_Transport_Smtp(&#039;other_server@example.com&#039;);
$mail-&gt;send($tr1);
$mail-&gt;send($tr2);
$mail-&gt;send();  // use default again
</pre>

    </div>

    <blockquote class="note"><p><b class="note">Note</b>: <span class="info"><b>Additional transports</b><br /></span>
        

        <p class="para">
            Additional transports can be written by implementing
            <span class="classname">Zend_Mail_Transport_Interface</span>.
        </p>
    </p></blockquote>

    <div class="section" id="zend.mail.file-transport"><div class="info"><h1 class="title">Using File Transport</h1></div>
    

    <p class="para">
        <span class="classname">Zend_Mail_Transport_File</span> is useful in a
        development environment or for testing purposes. Instead of sending any real
        emails it simply dumps the email&#039;s body and headers to a file in the filesystem.
        Like the other transports, it may be configured using
        <span class="classname">Zend_Application_Resource_Mail</span>, or by passing an instance to the
         <span class="methodname">send()</span> method of a <span class="classname">Zend_Mail</span> instance.
    </p>

    <p class="para">
        The transport has two optional parameters that can be passed to the constructor or
        via  <span class="methodname">setOptions()</span> method. The <span class="property">path</span>
        option specifies the base path where new files are saved. If nothing is set, the transport
        uses the default system directory for temporary files.  The second parameter,
        <span class="property">callback</span>, defines what PHP callback should be used to generate a
        filename. As an example, assume we need to use the recipient&#039;s email plus some
        hash as the filename:
    </p>

    <pre class="programlisting brush: php">
function recipientFilename($transport)
{
    return $transport-&gt;recipients . &#039;_&#039; . mt_rand() . &#039;.tmp&#039;;
}

$mail = new Zend_Mail();
$mail-&gt;addTo(&#039;somebody@example.com&#039;, &#039;Some Recipient&#039;);
// build message...
$tr = new Zend_Mail_Transport_File(array(&#039;callback&#039; =&gt; &#039;recipientFilename&#039;));
$mail-&gt;send($tr);
</pre>


    <p class="para">
        The resulting file will be something like <var class="filename">somebody@example.com_1493362665.tmp</var>
    </p>

    <blockquote class="note"><p><b class="note">Note</b>: <span class="info"><b>Include randomness in filename generation</b><br /></span>
        

        <p class="para">
            When generating filenames, you should inject some sort of randomness into the generation
            to ensure that the filenames are unique. This is especially important on servers where
            you may expect high load, as it will ensure that despite a number of requests coming in
            during the same second or millisecond, the filename will still be unique.
        </p>
    </p></blockquote>
</div>
</div>
        <hr />

            <table width="100%">
                <tr>
                    <td width="25%" style="text-align: left;">
                    <a href="zend.mail.multiple-emails.html">Sending Multiple Mails per SMTP Connection</a>
                    </td>

                    <td width="50%" style="text-align: center;">
                        <div class="up"><span class="up"><a href="zend.mail.html">Zend_Mail</a></span><br />
                        <span class="home"><a href="manual.html">Guia de Refer&ecirc;ncia do Programador</a></span></div>
                    </td>

                    <td width="25%" style="text-align: right;">
                        <div class="next" style="text-align: right; float: right;"><a href="zend.mail.html-mails.html">HTML E-Mail</a></div>
                    </td>
                </tr>
            </table>
</td>
        <td style="font-size: smaller;" width="15%"> <style type="text/css">
#leftbar {
	float: left;
	width: 186px;
	padding: 5px;
	font-size: smaller;
}
ul.toc {
	margin: 0px 5px 5px 5px;
	padding: 0px;
}
ul.toc li {
	font-size: 85%;
	margin: 1px 0 1px 1px;
	padding: 1px 0 1px 11px;
	list-style-type: none;
	background-repeat: no-repeat;
	background-position: center left;
}
ul.toc li.header {
	font-size: 115%;
	padding: 5px 0px 5px 11px;
	border-bottom: 1px solid #cccccc;
	margin-bottom: 5px;
}
ul.toc li.active {
	font-weight: bold;
}
ul.toc li a {
	text-decoration: none;
}
ul.toc li a:hover {
	text-decoration: underline;
}
</style>
 <ul class="toc">
  <li class="header home"><a href="manual.html">Guia de Refer&ecirc;ncia do Programador</a></li>
  <li class="header up"><a href="manual.html">Guia de Refer&ecirc;ncia do Programador</a></li>
  <li class="header up"><a href="reference.html">Refer&ecirc;ncia do Zend Framework</a></li>
  <li class="header up"><a href="zend.mail.html">Zend_Mail</a></li>
  <li><a href="zend.mail.introduction.html">Introduction</a></li>
  <li><a href="zend.mail.sending.html">Sending via SMTP</a></li>
  <li><a href="zend.mail.multiple-emails.html">Sending Multiple Mails per SMTP Connection</a></li>
  <li class="active"><a href="zend.mail.different-transports.html">Using Different Transports</a></li>
  <li><a href="zend.mail.html-mails.html">HTML E-Mail</a></li>
  <li><a href="zend.mail.attachments.html">Attachments</a></li>
  <li><a href="zend.mail.adding-recipients.html">Adding Recipients</a></li>
  <li><a href="zend.mail.boundary.html">Controlling the MIME Boundary</a></li>
  <li><a href="zend.mail.additional-headers.html">Additional Headers</a></li>
  <li><a href="zend.mail.character-sets.html">Character Sets</a></li>
  <li><a href="zend.mail.encoding.html">Encoding</a></li>
  <li><a href="zend.mail.smtp-authentication.html">SMTP Authentication</a></li>
  <li><a href="zend.mail.smtp-secure.html">Securing SMTP Transport</a></li>
  <li><a href="zend.mail.read.html">Reading Mail Messages</a></li>
 </ul>
 </td>
    </tr>
</table>

<script type="text/javascript" src="../js/shCore.js"></script>
<script type="text/javascript" src="../js/shAutoloader.js"></script>
<script type="text/javascript" src="../js/main.js"></script>

</body>
</html>